<template>
    <div>
        <div>
            <div style="display: flex;">
                <div style="width: 200px">
                    <el-input v-model="checkCode" placeholder="核销码（建议输入后6位）"></el-input>
                </div>
                <el-button @click="searchCode">查询</el-button>
            </div>

            <el-table :data="tableData" style="width: 100%" >
                <el-table-column prop="id" label="核销码" width="180">
                </el-table-column>
                <el-table-column label="奖品图片" width="180">
                    <template slot-scope="scope">
                        <el-image style="width: 60px; height: 60px" :src="scope.row.prizeUrl"></el-image>
                    </template>
                </el-table-column>
                <el-table-column prop="prizeName" label="奖品名" width="180"></el-table-column>
                <el-table-column prop="userName" label="用户名" width="180">
                </el-table-column>
                <el-table-column label="是否核销" width="180">
                    <template slot-scope="scope">
                        <el-tag :type="scope.row.useTime ? 'danger' : 'success'">
                        {{ scope.row.useTime ? '已核销' : '未核销'}}
                    </el-tag>

                    </template>
                </el-table-column>
                <el-table-column label="操作">
                    <template slot-scope="scope">
                        <el-button size="mini" @click="checkPrize(scope.row)">核销</el-button>
                    </template>
                </el-table-column>
            </el-table>
        </div>

    </div>
</template>
<script>
import { request } from '@/utils/request';
export default {
    name: "prizeCheck",
    data() {
        return {
            checkCode: '',
            tableData: [],
        };
    },
    methods: {
       
        checkStatus(useTime) {
           return useTime ? '已核销' : '未核销'
        },
        async searchCode() {
            if (!this.checkCode) {
                return this.$message.error('请输入核销码');
            }
            let data = await request.post('/prizecheck', {
                id: this.checkCode
            })
            data = data.data
            if (data.length == 0) {
                this.$message('没有查到数据');
            }
            this.tableData = data

        },
        async checkPrize(row) {
            let d = (await request.get('/check/prize/' + row.id))
            d = d.data
            if (d) {
                this.$message('核销成功');
            } else {
                this.$message('核销失败');
            }
        },


    }
}
</script>